cmake_minimum_required(VERSION 3.5)

project(enc28j60)

set(lwipcore_SRCS
    ${LWIP_DIR}/src/core/init.c
    ${LWIP_DIR}/src/core/def.c
    ${LWIP_DIR}/src/core/dns.c
    ${LWIP_DIR}/src/core/inet_chksum.c
    ${LWIP_DIR}/src/core/ip.c
    ${LWIP_DIR}/src/core/mem.c
    ${LWIP_DIR}/src/core/memp.c
    ${LWIP_DIR}/src/core/netif.c
    ${LWIP_DIR}/src/core/pbuf.c
    ${LWIP_DIR}/src/core/raw.c
    ${LWIP_DIR}/src/core/stats.c
    ${LWIP_DIR}/src/core/sys.c
    ${LWIP_DIR}/src/core/altcp.c
    ${LWIP_DIR}/src/core/altcp_alloc.c
    ${LWIP_DIR}/src/core/altcp_tcp.c
    ${LWIP_DIR}/src/core/tcp.c
    ${LWIP_DIR}/src/core/tcp_in.c
    ${LWIP_DIR}/src/core/tcp_out.c
    ${LWIP_DIR}/src/core/timeouts.c
    ${LWIP_DIR}/src/core/udp.c
)
set(lwipcore4_SRCS
    ${LWIP_DIR}/src/core/ipv4/autoip.c
    ${LWIP_DIR}/src/core/ipv4/dhcp.c
    ${LWIP_DIR}/src/core/ipv4/etharp.c
    ${LWIP_DIR}/src/core/ipv4/icmp.c
    ${LWIP_DIR}/src/core/ipv4/igmp.c
    ${LWIP_DIR}/src/core/ipv4/ip4_frag.c
    ${LWIP_DIR}/src/core/ipv4/ip4.c
    ${LWIP_DIR}/src/core/ipv4/ip4_addr.c
)

set(lwipnetif_SRCS
    ${LWIP_DIR}/src/netif/ethernet.c
)

set(lwipmqtt_SRCS
    ${LWIP_DIR}/src/apps/mqtt/mqtt.c
)

set(lwip_SRCS
    ${lwipcore_SRCS}
    ${lwipcore4_SRCS}
    ${lwipnetif_SRCS}
    ${lwipmqtt_SRCS}
)

set(enc28j60_SRCS
    ${lwip_SRCS}
    enc28j60.c
)

#set(CMAKE_C_FLAGS "-ggdb -ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS "-ggdb")

add_executable(enc28j60 ${enc28j60_SRCS})
target_include_directories(enc28j60 
    PRIVATE ${LWIP_DIR}/src/include
    PRIVATE include
)
target_compile_definitions(enc28j60
    PRIVATE LWIP_DEBUG=1
)
target_link_libraries(enc28j60 rt)
#set_target_properties(enc28j60 PROPERTIES LINK_FLAGS "-Wl,--gc-sections")
